// function request(url, params, success, fail) {
//   this.requestLoading(url, params, "", success, fail)
// }
// 展示进度条的网络请求
// url:网络请求的url
// params:post参数
// message:进度条的提示信息
// success:成功的回调函数
// fail：失败的回调

function getData(urls, params,success, fail ) {
  wx.showNavigationBarLoading()
  wx.showLoading({
    title: "正在加载",
  })
  wx.request({
    url:urls,
    data: params,
    header: {
      'content-Type': 'application/json'
      // 'content-type': 'application/x-www-form-urlencoded' 
    },
    method: "GET",
    success: function (res) {
      wx.hideNavigationBarLoading()     
      wx.hideLoading()     
      if (res.statusCode == 200) {
        success(res)
      }else{

      }
    },
    fail: function (res) {
      wx.hideNavigationBarLoading()      
      wx.hideLoading()       
      if (res.statusCode == 401) {
        fail(res)
      } else{
        wx.showModal({
          title: '提示',
          content: '加载失败请检查您的网络',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }   
    },
    complete: function (res) {
    },
  })
}
function postData(urls, params, success, fail) {
  wx.showNavigationBarLoading()  
    wx.showLoading({
      title: "正在加载",
    })  
  wx.request({
    url: urls,
    data: params,
    header: {
      'content-Type': 'application/json'
    },
    method: "POST",
    success: function (res) {
      // wx.hideNavigationBarLoading()    
      wx.hideLoading()     
      if (res.statusCode == 200) {
        success(res)
      } else {

      }
    },
    fail: function (res) {
      // wx.hideNavigationBarLoading()
      wx.hideLoading()
      if (res.statusCode == 401) {
        fail(res)
      } else {
        wx.showModal({
          title: '提示',
          content: '加载失败请检查您的网络',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    },
    complete: function (res) {
    },
  })
}

module.exports = {
  // request: request,
  postData: postData,
  getData: getData
}
